import { watcher } from "@feng3d/watcher";
import { Shape, ShapeGeometry } from "../../thirdparty/three/imports";
import { BufferGeometry3D } from "../core/BufferGeometry3D";

export class ShapeGeometry3D extends BufferGeometry3D
{
    shapes?: Shape | Shape[];
    curveSegments?: number;

    get _geometry()
    {
        if (!this.__geometry)
        {
            this.__geometry = new ShapeGeometry(this.shapes, this.curveSegments);
        }

        return this.__geometry;
    }
    declare protected __geometry: ShapeGeometry;

    constructor()
    {
        super();
        watcher.watchs(this as ShapeGeometry3D, ["shapes", "curveSegments"], this._invalidate, this);
    }

    destroy()
    {
        watcher.unwatchs(this as ShapeGeometry3D, ["shapes", "curveSegments"], this._invalidate, this);
    }
}
